package com.zhr.tea.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.zhr.tea.R;
import com.zhr.tea.view.adapter.DingdanViewpagerAdapter;
import com.zhr.tea.view.fragment.AcceptThingFragment;
import com.zhr.tea.view.fragment.AllDingdanFragment;
import com.zhr.tea.view.fragment.PayFragment;
import com.zhr.tea.view.fragment.SendThingFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DingdanActivity extends AppCompatActivity {
    @BindView(R.id.product_back)
    ImageView productBack;
    @BindView(R.id.tab_dingdan)
    TabLayout tabDingdan;
    @BindView(R.id.vp_dingdan)
    ViewPager vpDingdan;
    private String[] title = new String[]{"全部", "待付款", "待发货", "待收货"};
    private DingdanViewpagerAdapter adapter;
    private List<Fragment> data = new ArrayList<>();
    int num = 0;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ding_dan);
        ButterKnife.bind(this);
        initView();
        Intent intent = getIntent();
        num = intent.getIntExtra("num", 4);
        initData();
//        TabLayout.Tab tab = tabDingdan.getTabAt(num);
        vpDingdan.setCurrentItem(num);
    }

    private void initData() {
        data.add(AllDingdanFragment.newInstance());
        data.add(PayFragment.newInstance());
        data.add(SendThingFragment.newInstance());
        data.add(AcceptThingFragment.newInstance());
        adapter.notifyDataSetChanged();
    }

    private void initView() {
        adapter = new DingdanViewpagerAdapter(getSupportFragmentManager(), data, title);
        vpDingdan.setAdapter(adapter);
        tabDingdan.setupWithViewPager(vpDingdan);

    }

    @OnClick(R.id.product_back)
    public void onClick() {
        finish();
    }
}
